using JaegerDemo.Events;
using JaegerDemo.Shared;
using JaegerDemo.Shared.Options;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHttpClient();
builder.Services.AddOpenTracing();
var jaegerOptions = builder.Configuration.GetSection(JaegerOptions.Default).Get<JaegerOptions>();
builder.Services.AddJaegerTracer(jaegerOptions, builder.Environment.ApplicationName);
var rabbitMQOptions = builder.Configuration.GetSection(RabbitMQOptions.Default).Get<RabbitMQOptions>();
builder.Services.AddMasstransitEventBus(rabbitMQOptions, new MasstransitExtensions.EventBusConfigures()
{
    MasstransitConfigure = x =>
    {
        var queueName = "events-valuecreated";
        var serviceAddress = $"rabbitmq://{rabbitMQOptions.Host}:{rabbitMQOptions.Port}/{queueName}";
        x.AddRequestClient<ValueCreatedIntegrationEvent>(new Uri(serviceAddress));
    }
});
var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();